package com.example.coinhelper.utils;
import static android.content.Context.MODE_PRIVATE;

import com.example.coinhelper.Bean.Details;


import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import android.content.Context;

public class ExportUtil {

    public static boolean exportToExcel(List<Details> detailsList, String filePath) {
        return false;
    }
    public static Boolean exportToTxt(Context context,List<Details> detailsList, String filePath){
        String head = "\tID\t\t用户名\t\t\t日期\t\t\t\t类型\t\t支出/收入\t\t\t 备注\t\t\t\n";
        try{
            FileOutputStream fos = context.openFileOutput(filePath, Context.MODE_PRIVATE);
            fos.write(head.getBytes(StandardCharsets.UTF_8));
            for (Details details : detailsList) {
                String detailsString = String.format(
                        "\t%d          %s     %s    %s    %.2f  %s\n",
                        details.getId(),
                        details.getUsername(),
                        details.getDate(),
                        details.getOperation(),
                        details.getMoney(),
                        details.getOther()
                );
                fos.write(detailsString.getBytes(StandardCharsets.UTF_8));
            }
            fos.close();
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }

}
